/***************************************************************************************************
  *Copyright(C),2010-2016,Sumscope
  *FileName	:  ITableCache.h
  *Author	:  scofined.qi
  *Version	:  1.0
  *Date		:  2016/09/18
  *Desc		:  //用于主要说明此程序文件完成的主要功能
  *Relation :  
  *Others	:  //其他内容说明
  *Function :  //主要函数列表，每条记录应包含函数名及功能简要说明
  *History	:  //修改历史记录列表，每条修改记录应包含修改日期、修改者及修改内容简介
***************************************************************************************************/
#pragma once

#include "TableCommon.h"
#include "QuotaMap.h"
#include <string.h>
#include <string>

namespace qb{
	namespace ht{
		class TableFile;
		class ITableCache{
		public:
			ITableCache(){}
			virtual ~ITableCache(){};
			virtual void SetViewSize(int view){ }
			virtual void SetIncreaseSize(int increase){ }
			virtual void SetTempFile(bool temp){}

			// 新增接口用于处理映射文件头部
			virtual int GetHeadSize()=0;
			virtual bool ReadHead(char*buf, int size)=0;
			virtual bool WriteHead(const char*buf, int size, int count) = 0;
			virtual void BuildKeyMap(int count, int offset, int flagOffset = -1) = 0;
			virtual bool RemoveKey(const char* key) = 0;
            virtual void GetAllRecord(std::vector<unsigned int>& records){}

			// 新增接口用于指示对应的磁盘文件名称
			virtual const std::string& GetName() = 0;
			virtual void SetName(const std::string& fullFileName)=0;
			virtual void SetTag(const std::string& tag) = 0;

			virtual int GetRecordCount()const = 0;
			virtual int GetRecordLength()const = 0;
			virtual bool Read(RecordId rid, char* record, int size) = 0;
			virtual RecordId GetRecordId(const char* key) = 0;
			virtual RecordId Write(RecordId rid, const void* record, int size, const char* key,bool direct=false) = 0;
			virtual int GetMaxRecordId()const = 0;
			virtual TableFile* GetFile() = 0;
			virtual TableFile* RecreateFile() = 0;
			virtual void SetQuotaListener(QuotaMap::Listener* listener) = 0;
			virtual void SetCapcity(int capcity){};
			virtual void Flush(){}

			virtual int GetMemoryBytes()const{ return 0; }
			virtual int GetKeyBytes()const{ return 0; }
			virtual int GetSwapCount()const{ return 0; }
			virtual int GetWriteCount()const{ return 0; }
			virtual int GetQuotaCapcity()const{ return 0; }
			virtual int GetQuotaLength()const{ return 0; }
		};
	}//namespace ht
}//namespace qb
